home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / util / Mac F2C 1.3.sit / Mac F2C 1.3 / Test Project ƒ / F2Cmain.c < prev    next >
Text File  |  1995-09-17  |  4KB  |  219 lines

  1. /* STARTUP PROCEDURE FOR TRANSLATED FORTRAN PROGRAMS */
  2.  
  3. /* IMT 9Sep95  Modified for new conditional compile mechanism */
  4. #if ( defined(THINK_C) || defined(THINK_CPLUS) )
  5. #define TPM_F2C            
  6. #endif
  7.  
  8. /* IMT 9Sep95  Modified for new conditional compile mechanism */
  9. #if (  defined(SYMANTEC_C) || defined(SYMANTEC_CPLUS) )
  10. #define SPM_F2C
  11. #endif
  12.  
  13. /* IMT 9Sep95  Modified for new conditional compile mechanism */
  14. #if !defined(MPW_CW_F2C) && ( defined(__MWERKS__) )
  15. #define CW_F2C
  16. #endif
  17.  
  18. /* IMT 9Sep95  THINK Project Manager specific includes */
  19. #ifdef TPM_F2C
  20. #include <console.h>
  21. #endif                    
  22.  
  23. /* IMT 9Sep95  Symantec Project Manager specific includes */
  24. #ifdef SPM_F2C 
  25. #include <console.h>    
  26. #endif                    
  27.  
  28. /* IMT 9Sep95  CodeWarrior specific includes */
  29. #ifdef CW_F2C
  30. #include <console.h>
  31. #include <SIOUX.h>
  32. #endif
  33.  
  34. /* IMT 9Sep95  MPW CodeWarrior specific includes */
  35. #ifdef MPW_CW_F2C
  36. #include <console.h>
  37. #endif
  38.  
  39.  
  40. /* IMT 9Sep95  Prototypes for new functions that add multitasking */
  41. #if defined(TPM_F2C) || defined(SPM_F2C) || defined(CW_F2C) 
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. void InitMultiTask( long sliceInMicroSecs );
  46. void EndMultiTask( void );
  47. #ifdef __cplusplus
  48. }
  49. #endif
  50. #endif /* Macintosh C compilers */
  51.  
  52.  
  53. /* IMT 10Sep95  Declare jump buffer used to recover from exception exits & aborts */
  54. #if defined(TPM_F2C) || defined(SPM_F2C) || defined(CW_F2C) 
  55. #include <setjmp.h>
  56. #ifdef __cplusplus
  57. extern "C" {
  58. #endif
  59. jmp_buf gRecoverToConsole;
  60. #ifdef __cplusplus
  61. }
  62. #endif
  63. #endif /* Macintosh C compilers */
  64.  
  65.  
  66. #include "stdio.h"
  67. #include "signal.h"
  68.  
  69. #ifndef SIGIOT
  70. #ifdef SIGABRT
  71. #define SIGIOT SIGABRT
  72. #endif
  73. #endif
  74.  
  75.  
  76. #ifndef KR_headers
  77. #include "stdlib.h"
  78. #endif
  79. #ifdef __cplusplus
  80. extern "C" {
  81. #endif
  82.  
  83. #ifdef NO__STDC
  84. #define ONEXIT onexit
  85. extern void f_exit();
  86. #else
  87. #ifndef KR_headers
  88. extern void f_exit(void);
  89. #ifndef NO_ONEXIT
  90. #define ONEXIT atexit
  91. extern int atexit(void (*)(void));
  92. #endif
  93. #else
  94. #ifndef NO_ONEXIT
  95. #define ONEXIT onexit
  96. extern void f_exit();
  97. #endif
  98. #endif
  99. #endif
  100.  
  101. #ifdef KR_headers
  102. extern void f_init(), sig_die();
  103. extern int MAIN__();
  104. #define Int /* int */
  105. #else
  106. extern void f_init(void), sig_die(char*, int);
  107. extern int MAIN__(void);
  108. #define Int int
  109. #endif
  110.  
  111. static void sigfdie(Int n)
  112. {
  113. sig_die("Floating Exception", 1);
  114. }
  115.  
  116.  
  117. static void sigidie(Int n)
  118. {
  119. sig_die("IOT Trap", 1);
  120. }
  121.  
  122. #ifdef SIGQUIT
  123. static void sigqdie(Int n)
  124. {
  125. sig_die("Quit signal", 1);
  126. }
  127. #endif
  128.  
  129.  
  130. static void sigindie(Int n)
  131. {
  132. sig_die("Interrupt", 0);
  133. }
  134.  
  135. static void sigtdie(Int n)
  136. {
  137. sig_die("Killed", 0);
  138. }
  139.  
  140. #ifdef SIGTRAP
  141. static void sigtrdie(Int n)
  142. {
  143. sig_die("Trace trap", 1);
  144. }
  145. #endif
  146.  
  147.  
  148.  
  149. int xargc;
  150. char **xargv;
  151.  
  152. #ifdef KR_headers
  153. main(argc, argv) int argc; char **argv;
  154. #else
  155. main(int argc, char **argv)
  156. #endif
  157. {
  158.  
  159. /* IMT 9Sep95  Add file re-direction and command-line arguments dialog */
  160. #if defined(TPM_F2C) || defined(SPM_F2C) || defined(CW_F2C) 
  161.     argc = ccommand( &argv );
  162. #endif /* Macintosh C compilers */
  163.  
  164. /* IMT 14Sep95  Initialize multi-tasking code for CodeWarrior */
  165. #if defined(TPM_F2C) || defined(SPM_F2C) || defined(CW_F2C) 
  166.     InitMultiTask( 0 );
  167. #endif /* CodeWarrior */
  168.  
  169. xargc = argc;
  170. xargv = argv;
  171. signal(SIGFPE, sigfdie);    /* ignore underflow, enable overflow */
  172. #ifdef SIGIOT
  173. signal(SIGIOT, sigidie);
  174. #endif
  175. #ifdef SIGTRAP
  176. signal(SIGTRAP, sigtrdie);
  177. #endif
  178. #ifdef SIGQUIT
  179. if(signal(SIGQUIT,sigqdie) == SIG_IGN)
  180.     signal(SIGQUIT, SIG_IGN);
  181. #endif
  182. if(signal(SIGINT, sigindie) == SIG_IGN)
  183.     signal(SIGINT, SIG_IGN);
  184. signal(SIGTERM,sigtdie);
  185.  
  186. #ifdef pdp11
  187.     ldfps(01200); /* detect overflow as an exception */
  188. #endif
  189.  
  190. f_init();
  191. #ifndef NO_ONEXIT
  192. ONEXIT(f_exit);
  193. #endif
  194.  
  195. /* IMT 10Sep95:  Set-up for returning to console from exceptional exits and aborts */
  196. #if defined(TPM_F2C) || defined(SPM_F2C) || defined(CW_F2C)
  197. if ( setjmp(gRecoverToConsole) == 0 )
  198. #endif /* Macintosh C compilers */
  199.  
  200. MAIN__();
  201.  
  202. /* IMT 10Sep95:  Close out multi-tasking code for CW, SPM, TPM */
  203. #if defined(TPM_F2C) || defined(SPM_F2C) || defined(CW_F2C) 
  204. EndMultiTask();
  205. puts( "\nExecution complete.\n" );
  206. #endif /* Macintosh C compilers */
  207.  
  208.  
  209. #ifdef NO_ONEXIT
  210. f_exit();
  211. #endif
  212. exit(0);    /* exit(0) rather than return(0) to bypass Cray bug */
  213. return 0;    /* For compilers that complain of missing return values; */
  214.             /* others will complain that this is unreachable code. */
  215. }
  216. #ifdef __cplusplus
  217.     }
  218. #endif
  219.